<script setup lang="jsx">
import { reactive, ref } from 'vue';
import { DeleteOutlined, EditOutlined, PlusOutlined, SearchOutlined } from '@ant-design/icons-vue';
import useResetTableRef from '@/hooks/common/resetTableRef';
import useSearchData from '@/hooks/common/searchData';
import { vcpget, vcppost } from '@/service/api/modules/erp';
// import { deleteData } from '@/service/api/modules/material-management/open-sheet-use-record';
import { getTechNameSelect } from '@/service/api/modules/scrap-judgment';
import Add from './modules/add.vue';
const selectedDefect = ref(null);

const [searchParams, resetSearchParams] = useResetTableRef({
  prodNo: null,
  lotNo: null,
  time: null
});
// 批卡号搜索的弹窗查询
const [searchParams2, resetSearchParamsLot] = useResetTableRef({
  pageNum: 1,
  pageSize: 200,
  lotNo: null,
  prodNo: null,
  techName: null
});

const disabled = ref(false);
const tableRef = ref(null);
const tableRefs = ref(null);
const searchData = useSearchData(searchParams);
const searchDataLot = useSearchData(searchParams2);
const searchFormList = [
  {
    type: 'input',
    key: 'prodNo',
    label: '生产型号',
    span: 24,
    md: 12,
    lg: 10,
    xl: 4,
    xxl: 4,
    placeholder: '请输入生产型号',
    showTime: true
  },
  {
    type: 'input',
    key: 'lotNo',
    label: '批卡号',
    span: 24,
    md: 12,
    lg: 10,
    xl: 8,
    xxl: 4,
    placeholder: '请输入批卡号',
    showTime: true
  },
  {
    type: 'dateRangePicker',
    key: 'time',
    label: '日期',
    span: 24,
    md: 12,
    lg: 10,
    xl: 8,
    xxl: 6,
    showTime: true // 显示时分秒选择
  }
];

const pagination = reactive({
  current: 1,
  pageSize: 25,
  showSizeChanger: true,
  pageSizeOptions: ['50', '100', '200', '300', '500'],
  showQuickJumper: true,
  showTotal: total => {
    return `共${total}条`;
  },
  total: 0,
  onChange: async (current, size) => {
    pagination.current = current;
    pagination.pageSize = size;
  }
});
// 批卡号搜索
const detailsVisibleZyd = ref(false);
function handleSearch() {
  detailsVisibleZyd.value = true;
}
// 上表格
const columns = ref([
  {
    key: 'index',
    dataIndex: 'dataIndex',
    title: '序号',
    width: 80,
    align: 'center',
    checked: true,
    class: 'index-column'
  },
  {
    key: 'state',
    dataIndex: 'state',
    title: '状态',
    width: 100,
    align: 'center',
    checked: true,
    ellipsis: true,
    sorter: true
  },
  {
    key: 'requestNo',
    dataIndex: 'requestNo',
    title: '申请单号',
    width: 150,
    align: 'center',
    checked: true,
    ellipsis: true,
    sorter: true
  },
  {
    key: 'mrbno',
    dataIndex: 'mrbno',
    title: 'mrbno',
    width: 110,
    align: 'center',
    checked: true,
    ellipsis: true,
    sorter: true
  },
  {
    key: 'lotNo',
    dataIndex: 'lotNo',
    title: '批卡号',
    width: 150,
    align: 'center',
    checked: true,
    ellipsis: true,
    sorter: true
  },
  {
    key: 'fullProdNo',
    dataIndex: 'fullProdNo',
    title: '生产型号',
    width: 150,
    align: 'center',
    checked: true,
    ellipsis: true,
    // 对产品型号进行排序
    sorter: true
  },
  {
    key: 'deptCaption',
    dataIndex: 'deptCaption',
    title: '厂区',
    align: 'center',
    width: 120,
    checked: true,
    ellipsis: true
    // 对数量进行排
  },
  {
    key: 'techNo',
    dataIndex: 'techNo',
    title: '工艺编码',
    width: 130,
    align: 'center',
    checked: true,
    ellipsis: true,
    sorter: true
  },
  {
    key: 'techName',
    dataIndex: 'techName',
    title: '申请工艺',
    width: 130,
    align: 'center',
    checked: true,
    ellipsis: true,
    sorter: true
  },
  {
    key: 'pnType',
    dataIndex: 'pnType',
    title: '型号类型',
    width: 100,
    align: 'center',
    checked: true,
    ellipsis: true,
    sorter: true
  },
  {
    key: 'surfTrea1',
    dataIndex: 'surfTrea1',
    title: '表面处理1',
    width: 130,
    align: 'center',
    checked: true,
    ellipsis: true,
    sorter: true
  },
  {
    key: 'surfTrea2',
    dataIndex: 'surfTrea2',
    title: '表面处理2',
    width: 130,
    align: 'center',
    checked: true,
    ellipsis: true,
    sorter: true
  },
  {
    key: 'scrapCharacteristic',
    dataIndex: 'scrapCharacteristic',
    title: '报废特性',
    width: 130,
    align: 'center',
    checked: true,
    ellipsis: true,
    sorter: true
  },
  {
    key: 'rquQty',
    dataIndex: 'rquQty',
    title: '申请数量',
    width: 120,
    align: 'center',
    checked: true,
    ellipsis: true,
    sorter: true,
    customRender: ({ record }) => {
      // 字体加粗且是红色
      return <span class="fonw-900 color-red">{record.rquQty}</span>;
    }
  },
  {
    key: 'rquUnit',
    dataIndex: 'rquUnit',
    title: '申请单位',
    width: 120,
    align: 'center',
    checked: true,
    ellipsis: true,
    sorter: true
  },
  {
    key: 'rquScrapSet',
    dataIndex: 'rquScrapSet',
    title: '含废SET数',
    width: 120,
    align: 'center',
    checked: true,
    ellipsis: true,
    sorter: true
  },
  {
    key: 'rquScrapPcs',
    dataIndex: 'rquScrapPcs',
    title: '含废PCS数',
    width: 120,
    align: 'center',
    checked: true,
    ellipsis: true,
    sorter: true
  },
  {
    key: 'remark',
    dataIndex: 'remark',
    title: '备注',
    align: 'center',
    width: 150,
    checked: true,
    ellipsis: true
  },
  {
    key: 'scrapPnlQty',
    dataIndex: 'scrapPnlQty',
    title: '判定PNL数',
    align: 'center',
    width: 130,
    checked: true,
    ellipsis: true,
    sorter: true
  },
  {
    key: 'scrapSetQty',
    dataIndex: 'scrapSetQty',
    title: '判定SET数',
    align: 'center',
    width: 130,
    checked: true,
    ellipsis: true,
    sorter: true
  },
  {
    key: 'scrapPcsQty',
    dataIndex: 'scrapPcsQty',
    title: '判定PCS数',
    align: 'center',
    width: 130,
    checked: true,
    ellipsis: true,
    sorter: true
  },
  {
    key: 'pnlSet',
    dataIndex: 'pnlSet',
    title: '1PNL=?SET',
    align: 'center',
    width: 130,
    checked: true,
    ellipsis: true,
    sorter: true
  },
  {
    key: 'setPcs',
    dataIndex: 'setPcs',
    title: '1SET=?PCS',
    width: 130,
    align: 'center',
    checked: true,
    ellipsis: true,
    sorter: true
  },
  {
    key: 'pcsArea',
    dataIndex: 'pcsArea',
    title: '单元面积',
    align: 'center',
    width: 150,
    checked: true,
    ellipsis: true,
    sorter: true
  },
  {
    key: 'dateCode',
    dataIndex: 'dateCode',
    title: '周期',
    width: 120,
    align: 'center',
    checked: true,
    ellipsis: true,
    sorter: true
  },
  {
    key: 'createBy',
    dataIndex: 'createBy',
    title: '申请人',
    width: 120,
    align: 'center',
    checked: true,
    ellipsis: true,
    sorter: true
  },
  {
    key: 'createDate',
    dataIndex: 'createDate',
    title: '申请日期',
    align: 'center',
    width: 180,
    checked: true,
    ellipsis: true,
    sorter: true
  }
]);
// 下表格
const columns1 = ref([
  {
    key: 'index',
    dataIndex: 'dataIndex',
    title: '序号',
    width: 70,
    align: 'center',
    checked: true,
    ellipsis: true,
    class: 'index-column'
  },
  {
    key: 'deptCaption',
    dataIndex: 'deptCaption',
    title: '责任部门',
    sorter: true,
    align: 'center',
    checked: true,
    ellipsis: true
  },
  {
    key: 'techName',
    dataIndex: 'techName',
    title: '责任工艺',
    sorter: true,
    align: 'center',
    checked: true,
    ellipsis: true
  },
  {
    key: 'ltBugName',
    dataIndex: 'ltBugName',
    title: '缺陷名称',
    sorter: true,
    align: 'center',
    checked: true,
    ellipsis: true
  },
  {
    key: 'pnlQty',
    dataIndex: 'pnlQty',
    title: '判定PNL数',
    sorter: true,
    align: 'center',
    checked: true,
    ellipsis: true
  },
  {
    key: 'setQty',
    dataIndex: 'setQty',
    title: '判定SET数',
    width: 200,
    sorter: true,
    align: 'center',
    checked: true,
    ellipsis: true
  },
  {
    key: 'pcsQty',
    dataIndex: 'pcsQty',
    title: '判定PCS数',
    sorter: true,
    align: 'center',
    checked: true,
    ellipsis: true
  },
  {
    key: 'unitArea',
    dataIndex: 'unitArea',
    title: '单元面积',
    width: 200,
    sorter: true,
    align: 'center',
    checked: true,
    ellipsis: true
  },
  {
    key: 'scrapArea',
    dataIndex: 'scrapArea',
    title: '报废面积',
    sorter: true,
    align: 'center',
    checked: true,
    ellipsis: true
  },
  {
    key: 'createBy',
    dataIndex: 'createBy',
    title: '判定人',
    sorter: true,
    align: 'center',
    checked: true,
    ellipsis: true
  },
  {
    key: 'createDate',
    dataIndex: 'createDate',
    title: '判定日期',
    sorter: true,
    align: 'center',
    checked: true,
    ellipsis: true
  }
]);
// 新增弹窗中的责任表单
const columns2 = ref([
  {
    key: 'index',
    dataIndex: 'index',
    title: '序号',
    width: 70,
    align: 'center',
    checked: true,
    ellipsis: true
  },
  {
    key: 'deptCaption',
    dataIndex: 'deptCaption',
    title: '责任部门',
    width: 120,
    sorter: true,
    align: 'center',
    checked: true,
    ellipsis: true
  },
  {
    key: 'techName',
    dataIndex: 'techName',
    title: '责任工艺',
    width: 120,
    sorter: true,
    align: 'center',
    checked: true,
    ellipsis: true
  },
  {
    key: 'ltBugName',
    dataIndex: 'ltBugName',
    title: '缺陷名称',
    width: 130,
    sorter: true,
    align: 'center',
    checked: true,
    ellipsis: true
  },
  {
    key: 'pnlQty',
    dataIndex: 'pnlQty',
    title: '判定PNL数',
    width: 110,
    sorter: true,
    align: 'center',
    checked: true,
    ellipsis: true
  },
  {
    key: 'setQty',
    dataIndex: 'setQty',
    title: '判定SET数',
    width: 110,
    sorter: true,
    align: 'center',
    checked: true,
    ellipsis: true
  },
  {
    key: 'pcsQty',
    dataIndex: 'pcsQty',
    title: '判定PCS数',
    sorter: true,
    align: 'center',
    checked: true,
    ellipsis: true,
    width: 110
  },
  {
    key: 'remark',
    dataIndex: 'remark',
    title: '备注',
    sorter: true,
    align: 'center',
    checked: true,
    ellipsis: true,
    width: 150
  }
]);
// 查询MRB判定数据
// 查询MRB判定数据
const formList = [
  {
    type: 'tabs',
    name: 'MRB判定',
    span: 24
  },

  {
    type: 'input',
    key: 'lotNo',
    label: '批卡号',
    placeholder: '请选择批卡号',
    // 不可输出
    // disabled: true,
    // 必填
    rule: {
      required: true,
      message: '请选择批卡号',
      trigger: 'change'
    },
    suffixSlot: <SearchOutlined class="cursor-pointer" onClick={() => handleSearch()} />,
    span: 8
  },
  {
    type: '',
    name: '',
    span: 8
  },

  {
    type: '',
    name: '',
    span: 8
  },

  {
    type: 'input',
    key: 'requestNo',
    label: '申请单号',
    span: 8,
    disabled: true
  },
  {
    type: 'input',
    key: 'fullProdNo',
    label: '生产型号',
    span: 8,
    disabled: true
  },
  {
    type: 'input',
    key: 'custProdNo',
    label: '客户型号',
    span: 8,
    disabled: true
  },
  {
    type: 'input',
    key: 'pnlSet',
    label: '1PNL=?SET',
    span: 8,
    disabled: true
  },
  {
    type: 'input',
    key: 'setPcs',
    label: '1SET=?PCS',
    span: 8,
    disabled: true
  },
  {
    type: 'input',
    key: 'deptCaption',
    label: '申请部门',
    span: 8,
    disabled: true
  },
  {
    type: 'input',
    key: 'techName',
    label: '申请工艺',
    span: 8,
    disabled: true
  },
  {
    type: 'input',
    key: 'wipUnit',
    label: '申请单位',
    span: 8,
    disabled: true
    // 如果返回值是PNL，申请含费SET输入框不可输入
  },
  {
    type: 'input',
    key: 'scrapCharacteristic',
    label: '报废特性',
    span: 8,
    disabled: true,
    // 提示信息
    placeholder: 'null费null'
  },
  {
    type: 'input',
    key: 'wipQty',
    label: '数　　量',
    span: 8,
    disabled: true
    // lable字体颜色
  },
  {
    type: 'input',
    key: 'surfTrea1',
    label: '表面处理1',
    span: 8,
    disabled: true
  },
  {
    type: 'input',
    key: 'mrbno',
    label: 'MRBNo',
    span: 8,
    disabled: true
  },
  {
    type: 'inputNumber',
    key: 'rquQty',
    label: '申请数量',
    span: 8
  }
];
const detailsVisible = ref(false);
const detailsVisibleRes = ref(false);
const searchParams1 = ref({
  pageNum: 1,
  pageSize: 25,
  requestId: ''
});
const selectedEditData = ref(null);
const upDatas = ref('');
const upDataP = ref('');
const addDatas = ref('');
const titles = ref('');
const titleP = ref('');

function addData() {
  // 申请数量值默认为1
  titles.value = '报废申请单新增';
  upDatas.value = {
    // 申请数量值默认为1
    rquQty: 1,
    rquScrapSet: 0,
    rquScrapPcs: 0,
    scrapPnlQty: 0,
    scrapSetQty: 0,
    scrapPcsQty: 0,
    lotNo: null
  };
  detailsVisible.value = true;
  // 点击新增按钮，获取MRB判定中的批卡号
  const lotNoData = upDatas.value.lotNo;
  console.log(lotNoData);
}

function search() {
  tableRef.value.getData(1);
}

function reset() {
  resetSearchParams();
  search();
}

function tableRowClick(val) {
  searchParams1.value.requestId = val.requestId;
  tableRefs.value.getData();
}

// 工艺名称类型下拉数据--接口获取
const techList = ref([]);
const searchFormListS = [
  {
    type: 'input',
    key: 'lotNo',
    label: '批卡号',
    span: 6,
    placeholder: '请输入批卡号',
    showTime: true
  },
  {
    type: 'input',
    key: 'prodNo',
    label: '生产型号',
    span: 6,
    placeholder: '请输入生产型号',
    showTime: true
  },
  {
    type: 'select',
    key: 'techName',
    label: '工艺名称',
    span: 6,
    placeholder: '请选择工艺名称',
    showTime: true,
    selectOptions: techList
  }
];
function getSystemList() {
  getTechNameSelect().then(({ data, error }) => {
    techList.value = data?.map(item => {
      return {
        label: item,
        value: item
      };
    });
  });
}
getSystemList();

const tableDataLot = ref([]);
// 批卡号搜索
const columnsS = ref([
  {
    key: 'index',
    dataIndex: 'index',
    title: '序号',
    width: 60,
    align: 'center',
    checked: true
  },
  {
    key: 'pnType',
    dataIndex: 'pnType',
    title: '型号类型',
    sorter: true,
    align: 'center',
    checked: true,
    width: 100
  },
  {
    key: 'fullProdNo',
    dataIndex: 'fullProdNo',
    title: '生产型号',
    sorter: true,
    align: 'center',
    checked: true,
    width: 130
  },
  {
    key: 'lotNo',
    dataIndex: 'lotNo',
    title: '批卡号',
    sorter: true,
    align: 'center',
    checked: true,
    width: 150,
    // 颜色为蓝色
    customRender: ({ record }) => {
      // 字体加粗且是红色
      return <span class="color-#646cff">{record.lotNo}</span>;
    }
  },
  {
    key: 'techName',
    dataIndex: 'techName',
    title: '工艺',
    sorter: true,
    align: 'center',
    checked: true,
    width: 140
  },
  {
    key: 'surfTrea1',
    dataIndex: 'surfTrea1',
    title: '表面处理1',
    sorter: true,
    align: 'center',
    checked: true,
    width: 180
  },
  {
    key: 'wipUnit',
    dataIndex: 'wipUnit',
    title: '单位',
    sorter: true,
    align: 'center',
    checked: true,
    width: 80
  },
  {
    key: 'wipQty',
    dataIndex: 'wipQty',
    title: '数量',
    sorter: true,
    align: 'center',
    checked: true,
    width: 80
  },
  {
    key: 'wipScrapPcs',
    dataIndex: 'wipScrapPcs',
    title: '含废PCS',
    sorter: true,
    align: 'center',
    checked: true,
    width: 110
  },
  {
    key: 'outUnit',
    dataIndex: 'outUnit',
    title: '出账单位',
    sorter: true,
    align: 'center',
    checked: true,
    width: 120
  },
  {
    key: 'outQty',
    dataIndex: 'outQty',
    title: '出账数',
    sorter: true,
    align: 'center',
    checked: true,
    width: 120
  },
  {
    key: 'outScrapSet',
    dataIndex: 'outScrapSet',
    title: '出账SET',
    sorter: true,
    align: 'center',
    checked: true,
    width: 120
  },
  {
    key: 'outScrapPcs',
    dataIndex: 'outScrapPcs',
    title: '出账PCS',
    sorter: true,
    align: 'center',
    checked: true,
    width: 120
  },
  {
    key: 'createDate',
    dataIndex: 'createDate',
    title: '入账时间',
    sorter: true,
    align: 'center',
    checked: true,
    width: 160
  },
  {
    key: 'workState',
    dataIndex: 'workState',
    title: '生产状态',
    sorter: true,
    align: 'center',
    checked: true,
    width: 120
  },
  {
    key: 'wipState',
    dataIndex: 'wipState',
    title: '结存状态',
    sorter: true,
    align: 'center',
    checked: true,
    width: 120
  },
  {
    key: 'workDate',
    dataIndex: 'workDate',
    title: '生产时间',
    sorter: true,
    align: 'center',
    checked: true,
    width: 160
  },
  {
    key: 'finishDate',
    dataIndex: 'finishDate',
    title: '完成时间',
    sorter: true,
    align: 'center',
    checked: true,
    width: 160
  },
  {
    key: 'workDays',
    dataIndex: 'workDays',
    title: '生产时长',
    sorter: true,
    align: 'center',
    checked: true,
    width: 120
  },
  {
    key: 'unitArea',
    dataIndex: 'unitArea',
    title: '单元面积',
    sorter: true,
    align: 'center',
    checked: true,
    width: 150
  },
  {
    key: 'createBy',
    dataIndex: 'createBy',
    title: '入账员',
    sorter: true,
    align: 'center',
    checked: true,
    width: 120
  }
]);
// 批卡号搜索下列表
function getDataLot() {
  vcpget('/erpsyncmes/baseData/proscraprequest/scarpLotInfo/list', searchParams2.value).then(({ data, error }) => {
    if (!error) {
      data.list.forEach((item, index) => {
        item.index = index + 1;
      });
      tableDataLot.value = data.list; // 表格赋值
    }
  });
}
function searchLot() {
  getDataLot();
}
function resetLot() {
  resetSearchParamsLot();
  searchLot();
}
const dataListParams = ref([]);
// 点击批卡号数据赋值到新增表单
function tableRowClickP(val) {
  searchParams2.value.wipId = val;
  console.log(val);
  upDatas.value = val;
}
function addAssignment() {
  // 赋值给Form表单
  addDatas.value = searchParams2.value.wipId;
  // 申请数量值默认为1
  addDatas.value.rquQty = 1;
  addDatas.value.rquScrapSet = 0;
  addDatas.value.rquScrapPcs = 0;
  // 弹窗关闭
  disabled.value = false;
  if (addDatas.value.outUnit === 'SET') {
    disabled.value = true;
  }
  // 打印批卡号
  console.log(addDatas.value.lotNo);
  const lotNosearch = addDatas.value.lotNo;
  // 根据lotNosearch查询接口--- 判定数据
  vcpget('/erpsyncmes/baseData/proscraprequest/list', { prodNo: lotNosearch, pageSize: 200, pageNum: 1 }).then(
    ({ data, error }) => {
      if (!error) {
        // 赋值给Form表单
        addDatas.value.bugRequestLogList = data.list;
        console.log(addDatas.value.bugRequestLogList);
      }
    }
  );

  // 点击确定时候，清空dataListParams中的数据
  dataListParams.value = [];

  detailsVisibleZyd.value = false;
}

const upDatasA = ref({
  scrapPnlQty: 1,
  scrapSetQty: 0,
  scrapPcsQty: 0,
  pnlQty: 0,
  setQty: 0,
  pcsQty: 0
});

function handleAdd() {
  console.log('打印所选批卡信息', addDatas.value);
  if (upDatas.value.lotNo === null) {
    detailsVisibleRes.value = false;
    window.$message?.error('批卡号不能为空');
  } else {
    titleP.value = '新增责任判定';
    upDatasA.value = {
      scrapPnlQty: addDatas.value.rquQty,
      scrapSetQty: addDatas.value.pnlSet * addDatas.value.rquQty,
      scrapPcsQty: addDatas.value.pnlSet * addDatas.value.setPcs
    };
    detailsVisibleRes.value = true;
  }
}

// 更新 selectedDefect 状态
function tableRowClickAdd(record) {
  console.log('点击行的数据:', record);
  selectedDefect.value = record;
  if (record.bugId !== null) {
    console.log('打印批卡', record.bugId);
    selectedDefect.value = record;
  } else {
    selectedDefect.value = null;
  }
}

const addRef = ref(null);
// 添加责任判定
function addThe() {
  const addRefData = { ...addRef.value };
  const UpDatas = addRefData.upDatasA;
  console.log('upDatasA', UpDatas);

  const selecte = selectedDefect.value;
  if (selecte === null) {
    window.$message?.error('请选择报废缺陷');
    disabled.value = false;
  } else {
    const data = {
      ...UpDatas,
      ...selecte
    };
    console.log('合成的对象', data);
    dataListParams.value.push(data);
    dataListParams.value.forEach((item, index) => {
      item.index = index + 1;
    });
    dataListParams.value = [...dataListParams.value];
    window.$message?.success('新增成功');
  }
}
function handleSelectChange(val) {
  console.log(999);
  console.log('主页的选中值', val); // 主页的选中值
  dataListParams.value = val;
}

// 点击updata，弹出修改弹窗
function updata() {
  if (dataListParams.value.length != 1) {
    window.$message?.error('请选择要修改的单条数据');
  }
  titles.value = '报废申请单修改';
  // 将列表勾选的数据赋值给 弹出框的formListA的model
  upDatas.value = dataListParams.value;
  detailsVisible.value = true;
}

function handleRowClickRes(record) {
  console.log('点击行的数据:', record);
}

function handleSelectChangeRes(record) {
  console.log('修改跟删除选中的行:', record);
  selectedEditData.value = record;
  if (record.length === 1) {
    selectedEditData.value = record[0];
  } else {
    selectedEditData.value = null;
  }
}

// 新增弹窗中的责任判断修改
function updataZ(record) {
  if (!selectedEditData.value || selectedEditData.value.length === 0) {
    return window.$message?.error('请选择一条数据');
  }
  titleP.value = '责任判断修改';
  console.log('正在传值', selectedEditData.value);
  // 将列表勾选的数据赋值给 弹出框的formListA的model
  selectedEditData.value = record;

  detailsVisibleRes.value = true;
}
// 新增弹窗中的责任判断删除
function deleteDataD() {
  if (!selectedEditData.value) {
    return window.$message?.error('请选择一条数据');
  }
  window.$modal.confirm({
    title: '提示',
    content: '确认删除该行数据吗？',
    onOk() {
      // 删除选中的数据
      dataListParams.value.splice(selectedEditData.value.index - 1, 1);
      dataListParams.value.forEach((item, index) => {
        item.index = index + 1; // 重新分配 index
      });
      dataListParams.value = [...dataListParams.value];
      window.$message?.success('删除成功');
      // 如果删除的是最后一条数据，则清空selectedEditData
      if (dataListParams.value.length === 0) {
        selectedEditData.value = null;
      }
    },
    onCancel() {}
  });
}

// 主页数据新增
function getAddData() {
  if (upDatas.value.lotNo === null) {
    detailsVisibleRes.value = false;
    window.$message?.error('批卡号不能为空');
  } else {
    // 获取MRB判定中的数据
    const lotNoData = upDatas.value;
    console.log('上表格', lotNoData);
    // 当责任判定数据不为空时，调用接口新增数据
    console.log(1234, dataListParams.value);
    if (dataListParams.value.length > 0) {
      // 动态的获取责任判定表格中的数据
      const lastList = dataListParams.value;
      console.log('下表格', lastList);
      // 将下表格数据装入为bugRequestLogList数组里
      const bugRequestLogList = lastList.map(item => {
        return {
          bugId: item.bugId,
          techId: item.techId,
          deptId: item.deptId,
          pnlQty: item.pnlQty,
          setQty: item.setQty,
          pcsQty: item.pcsQty,
          remark: item.remark
        };
      });
      console.log('bugRequestLogList', bugRequestLogList);
      // 调用接口新增数据将lotNoData跟bugRequestLogList数据一起传过去
      vcppost('/erpsyncmes/baseData/proscraprequest/add/new/scrapLog', {
        ...lotNoData,
        bugRequestLogList
      }).then(({ data, error }) => {
        if (!error) {
          detailsVisible.value = false;
          addDatas.value = '';
          window.$message?.success('新增成功');
          selectedRowKeys.value = [];
          getData();
        }
      });
    } else {
      window.$message?.error('缺少责任判定数据');
    }
  }
}
</script>

<template>
  <div class="min-h-500px flex-col-stretch gap-16px overflow-hidden lt-sm:overflow-auto">
    <CommonSearch
      v-model:searchParams="searchParams"
      :form-list="searchFormList"
      @search="search"
      @reset="reset"
    ></CommonSearch>
    <div class="min-h-450px flex-col-stretch gap-16px overflow-hidden lt-sm:overflow-auto">
      <Table
        ref="tableRef"
        v-model:searchParams="searchData"
        :column="columns"
        :show-row-selection="true"
        :auto-generate-uuid="true"
        :row-height="24"
        :scroll="{ y: '450px' }"
        is-init-get-data
        url="/erpsyncmes/baseData/proscraprequest/list"
        @table-select-change="handleSelectChange"
        @table-row-click="tableRowClick"
      >
        <template #title>
          <span class="mr15px color-#646cff">报废申请单</span>
          <AButton type="primary" size="small" ghost class="mini-btn mr-8px" @click="addData">
            <template #icon>
              <PlusOutlined class="align-sub" />
            </template>
            新增
          </AButton>
          <AButton type="primary" size="small" ghost class="mini-btn mr-8px" @click="updata">
            <template #icon>
              <EditOutlined class="align-sub" />
            </template>
            修改
          </AButton>
        </template>
      </Table>
    </div>
    <!-- 下表格 -->
    <Table
      ref="tableRefs"
      v-model:searchParams="searchParams1"
      :column="columns1"
      :show-row-selection="false"
      :auto-generate-uuid="true"
      row-key="recId"
      :scroll="{ x: 'auto', y: 'auto' }"
      :row-height="24"
      url="/erpsyncmes/baseData/bugRequestLog/list"
      :is-init-get-data="false"
    >
      <template #title>
        <span class="mr15px color-#646cff">责任判定</span>
      </template>
    </Table>
    <!-- 新增 -->
    <!-- 新增 -->
    <!-- 新增 -->
    <Modal
      v-model:visible="detailsVisible"
      :destroy-on-close="true"
      :centered="true"
      :title="titles"
      width="1000px"
      height="750px"
    >
      <div v-if="titles == '型号定义修改'" class="event-form" style="margin-bottom: 20px">
        <Form v-model:model="upDatas" :form-list="formList"></Form>
      </div>
      <div v-else class="event-form" style="margin-bottom: 20px">
        <Form v-model:model="upDatas" :form-list="formList"></Form>
      </div>

      <!-- 责任判定的增删改 -->
      <div style="height: 200px">
        <Table
          ref="tableRefs"
          v-model:searchParams="searchParams1"
          :column="columns2"
          :show-row-selection="true"
          :auto-generate-uuid="false"
          row-key="index"
          :data-source="dataListParams"
          :scroll="{ x: 'auto', y: '150px' }"
          :is-init-get-data="false"
          @table-select-change="handleSelectChangeRes"
          @table-row-click="handleRowClickRes"
        >
          <template #title>
            <div style="margin-bottom: 10px">
              <span style="color: #646cff; margin-right: 10px">责任判定</span>
              <AButton type="primary" size="small" ghost class="mini-btn mr-8px" @click="handleAdd">
                <template #icon>
                  <PlusOutlined class="align-sub" />
                </template>
                新增
              </AButton>
              <AButton type="primary" size="small" ghost class="mini-btn mr-8px" @click="updataZ">
                <template #icon>
                  <EditOutlined class="align-sub" />
                </template>
                修改
              </AButton>
              <AButton type="primary" size="small" ghost class="mini-btn mr-8px" @click="deleteDataD">
                <template #icon>
                  <DeleteOutlined class="align-sub" />
                </template>
                删除
              </AButton>
            </div>
          </template>
        </Table>
      </div>
      <template #footer>
        <div class="modal-footer">
          <AButton @click="detailsVisible = false">关闭</AButton>
          <AButton v-if="titles == '判定修改'" @click="getAddData">保存</AButton>
          <AButton v-else @click="getAddData">保存</AButton>
        </div>
      </template>
    </Modal>

    <!-- 新增判定 -->
    <!-- 新增判定 -->
    <!-- 新增判定 -->
    <Modal
      v-model:visible="detailsVisibleRes"
      :destroy-on-close="true"
      :centered="true"
      :title="titleP"
      width="1200px"
      height="930px"
      mask
      :modal-warp-style="{ padding: '5px' }"
    >
      <div v-if="titleP == '责任判定添加'" class="event-form" style="margin-bottom: 20px">
        <Add v-model="upDataP" :up-datas-a="upDatasA" @row-clicked="tableRowClickAdd" />
      </div>
      <div v-else class="event-form" style="margin-bottom: 20px">
        <Add ref="addRef" v-model="upDataP" :up-datas-a="upDatasA" @row-clicked="tableRowClickAdd" />
      </div>
      <!-- 责任判定的保存添加 -->
      <template #footer>
        <div class="modal-footer">
          <AButton @click="detailsVisibleRes = false">关闭</AButton>
          <AButton v-if="titleP == '新增责任判定'" type="primary" @click="addThe">添加</AButton>
          <AButton v-else type="primary" @click="addThe">修改</AButton>
        </div>
      </template>
    </Modal>

    <!-- 批卡号搜索 -->
    <!-- 批卡号搜索 -->
    <!-- 批卡号搜索 -->
    <Modal
      v-model:visible="detailsVisibleZyd"
      :mask="true"
      :z-index="1001"
      :destroy-on-close="false"
      :centered="false"
      title="批卡号查询"
      width="1200px"
      height="800px"
    >
      <div class="h-full w-full flex-col-stretch gap-16px overflow-hidden lt-sm:overflow-auto">
        <CommonSearch
          v-model:searchParams="searchParams2"
          :form-list="searchFormListS"
          @search="searchLot"
          @reset="resetLot"
        ></CommonSearch>

        <Table
          ref="tableRefs"
          v-model:searchParams="searchDataLot"
          :column="columnsS"
          :show-row-selection="false"
          :show-card-header="false"
          :auto-generate-uuid="false"
          row-key="wipId"
          class="h-full"
          :scroll="{ x: 'auto', y: '500px' }"
          is-init-get-data
          :data-source="tableDataLot"
          :row-height="28"
          @table-row-click="tableRowClickP"
        ></Table>
      </div>

      <template #footer>
        <div style="display: flex">
          <div style="width: 40%; margin-left: 45%; margin-top: 0.5%; margin-right: 20px">
            <Form v-model:model="addDatas" :form-list="formListEidtThe"></Form>
          </div>
          <div>
            <AButton type="primary" @click="addAssignment">确定</AButton>
            <AButton @click="detailsVisibleZyd = false">关闭</AButton>
          </div>
        </div>
      </template>
    </Modal>
  </div>
</template>

<style lang="scss" scoped>
.row-red-background {
  background-color: rgba(244, 56, 56, 0.7) !important; /* !important 可能需要以确保覆盖其他样式 */
}
.expired {
  color: red;
  font-weight: bold;
  font-size: larger;
}

:deep(.surely-table-wrapper) {
  &.has-footer-table {
    .ant-spin-nested-loading {
      .ant-spin-container {
        .surely-table {
          height: calc(100% - 40px - v-bind('footerHeight')) !important;
        }
      }
    }
  }
}
</style>
